*** Replication Do-File for Figure 2 & Appendix 4 in BJPS Paper 'A New Dilemma of Social Democracy?' (19/09/23)

*** Pre-Clean Version

***********************************************************************************

version 14
clear all
set more off, perm
set scrollbufsize 300000
set maxvar 32767

cd "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data" 

use "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\BES2019_W21_Panel_v21.0.dta", clear //* BESIP Panel, Combined Wave 1-21 Internet Panel (2021 Release) - Later editions should also work fine 
	 
	 
	 
	  
* Note: For this pooled survey analysis need data in long format.  Hence need to take relevant BESIP waves (10,19,20,21) and merge them together.
	  
	  
********** WAVE 10 (2016) VARIABLE CONSTRUCTION
	 	 
drop if wave10 != 1	 
	
gen objectiveclassW10 =.
label define objectiveclassW10 1 "Old Middle Class" 2 "New Middle Class" 3 "Intermediate Class" 4 "Own Account" 5 "Foremen + Supervisors" 6 "Working Class" 7 "Other Outside Labour Force", replace
label variable objectiveclassW10 "Respondent Occupational Class"
label values objectiveclassW10 objectiveclassW10

replace objectiveclassW10 = 1 if inlist(ns_secW6W7W8W9,10,20,33,34,43,50,81,82,92)   //* OMC  (Employers, Managers, Administrators, Farmers, and Professionals Self-Employed, e.g. lawyers, doctors, psychologists, senior officers in police/NHS etc.)
replace objectiveclassW10 = 2 if inlist(ns_secW6W7W8W9,31,32,41,42,60) //* NMC  (Professional Employees + Higher Supervisors [e.g. office supervisors], e.g. web designers, nurses, teachers, social workers, scientists, engineers, physios)        
replace objectiveclassW10 = 3 if inlist(ns_secW6W7W8W9,71,72,73,74) //* Intermediate Classes (Lower white collar employees, Clerks, Call centre workers, sales teams, junior admin staff - i.e. classW19ic office workers - techies, IT staff, police etc)
replace objectiveclassW10 = 4 if inlist(ns_secW6W7W8W9,44,91) //* Own Account (importers and exporters, self employed tradespeople)
replace objectiveclassW10 = 5 if inlist(ns_secW6W7W8W9,100)  //* Foremen and Lower Supervisors
replace objectiveclassW10 = 6 if inrange(ns_secW6W7W8W9,111,135)  //* WC = Non-supervisory lower technical, semi-routine, and routine employees (e.g. metal workers, shelf fillers, security workers, porters, waiters, cleaners, drivers, telephone salespeople, checkout workers, employed hairdressers, care workers, scaffolders, cooks, employed craftspeople, childcare workers)

replace objectiveclassW10 = 1 if inrange(selfNumEmployeesW6_W12,1,9999)                          //* Assign employers to top category

replace objectiveclassW10 = 1 if selfOccStatusW6_W12 == 0 & inlist(objectiveclassW10,2)          //* Assign self-employed professionals to top category
replace objectiveclassW10 = 1 if selfOccStatusLastW6_W12 == 0 & inlist(objectiveclassW10,2)          //* Assign self-employed professionals to top category

replace objectiveclassW10 = 4 if selfOccStatusW6_W12 == 0 & inlist(objectiveclassW10,3,4,5,6,7)  //* Assign lower self-employed to own account
replace objectiveclassW10 = 4 if selfOccStatusLastW6_W12 == 0 & inlist(objectiveclassW10,3,4,5,6,7)  //* Assign lower self-employed to own account

replace objectiveclassW10 = 7 if ns_secW6W7W8W9 ==. & inlist(workingStatusW6_W12,4,5,6,7,8)      //* Assign missing to out of labour market 


gen degreeW10 =.
label define degreeW10 1 "University Degree or at Uni now" 0 "No University Degree"
label var    degreeW10   "Dummy: Has a University Degree or Equivalent, or is Currently at Uni"
label values degreeW10 degreeW10
replace degreeW10 = 1 if inlist(p_educationW10,13,14,15,16,17)
replace degreeW10 = 0 if degreeW10 != 1 & p_educationW10 !=. & p_educationW10 != 20


gen ethnicityW10 =.
label define ethnicityW10 1 "White" 2 "Non-White / Mixed", replace
label variable ethnicityW10 "Respondent Ethnicity"
label values ethnicityW10 ethnicityW10 

replace ethnicityW10 = 1 if inlist(p_ethnicityW10,1,2)    | ethnicityW10 == . & inlist(p_ethnicityW9,1,2)  | ethnicityW10 == . & inlist(p_ethnicityW11,1,2) 
replace ethnicityW10 = 2 if inrange(p_ethnicityW10,3,15)  | ethnicityW10 == . & inlist(p_ethnicityW9,3,15) | ethnicityW10 == . & inlist(p_ethnicityW11,3,15)  



gen whites_allclassesW10 =.
label var whites_allclassesW10 "Occupational Class (All White Respondents)"
label define whites_allclassesW10 1 "Old Middle Class" 2 "New Middle Class" 3 "Intermediate Class" 4 "Own Account" 5 "Foremen + Supervisors" 6 "Working Class" 7 "Unidentified / Out of Labour Market" 99 "Ethnic Minority", replace
label values whites_allclassesW10 whites_allclassesW10

replace whites_allclassesW10 = 1 if objectiveclassW10 == 1 & ethnicityW10 == 1
replace whites_allclassesW10 = 2 if objectiveclassW10 == 2 & ethnicityW10 == 1
replace whites_allclassesW10 = 3 if objectiveclassW10 == 3 & ethnicityW10 == 1
replace whites_allclassesW10 = 4 if objectiveclassW10 == 4 & ethnicityW10 == 1
replace whites_allclassesW10 = 5 if objectiveclassW10 == 5 & ethnicityW10 == 1
replace whites_allclassesW10 = 6 if objectiveclassW10 == 6 & ethnicityW10 == 1
replace whites_allclassesW10 = 7 if objectiveclassW10 == 7 & ethnicityW10 == 1
replace whites_allclassesW10 = 99 if ethnicityW10 == 2


gen ClassGroup_W10 =.
label define ClassGroup_W10 1 "White Working Class" 2 "White Graduates" 3 "Other Whites" 4 "Ethnic Minorities", replace
label values ClassGroup_W10 ClassGroup_W10

replace ClassGroup_W10 = 1 if whites_allclassesW10 == 6 & ethnicityW10 == 1 & degreeW10 == 0
replace ClassGroup_W10 = 2 if whites_allclassesW10 !=.  & ethnicityW10 == 1 & degreeW10 == 1
replace ClassGroup_W10 = 3 if ClassGroup_W10 ==.        & ethnicityW10 == 1 & degreeW10 != .
replace ClassGroup_W10 = 4 if ClassGroup_W10 ==.        & ethnicityW10 == 2 & degreeW10 != . 

gen UKcountryW10 =.
label variable UKcountryW10 "Constituent UK Country (W19 or Other Most Current)"
label define countryW10 1 "England" 2 "Wales" 3 "Scotland"
label values UKcountryW10 countryW10

replace UKcountryW10 = 1 if countryW10 == 1
replace UKcountryW10 = 2 if countryW10 == 3
replace UKcountryW10 = 3 if countryW10 == 2


* Female
gen female =.
replace female = 1 if gender == 2
replace female = 0 if gender == 1

rename Age age

gen agegrpW10 =.
label variable agegrpW10 "Age (4 Groups)"
label define agegrpW10 1 "18-25" 2 "26-44" 3 "45-64" 4 "65+"
label values agegrpW10 agegrpW10

replace agegrpW10 = 1 if inrange(ageW10,16,25)
replace agegrpW10 = 2 if inrange(ageW10,26,44)
replace agegrpW10 = 3 if inrange(ageW10,45,64)
replace agegrpW10 = 4 if inrange(ageW10,65,120)


* Ethnocentrism

order warmWhiteW11 warmAsianW11 warmBlackW11 warmWCW11 warmMCW11, after(partyIdSqueezeW21)

foreach var of varlist warmWhiteW11 -  warmMCW11 {
        replace `var' =. if `var' == 9999
}


gen warmBMEW11 = (warmAsianW11 + warmBlackW11)/2

gen ethnocentrismw11 = (warmWhiteW11 - warmBMEW11) / 10
label var ethnocentrismw11 "Respondent White Ethnocentrism (How Much More likes Whites than BME)"
label define ethno -10 "Wholly BMEcentric" 0 "Neutral" 10 "Wholly Whitecentric", replace
	 
		 
		
* Perceived Group Representation	

foreach var of varlist  labLookAfterBAW10 labLookAfterBAW19 labLookAfterBAW20 labLookAfterBAW21 {
        replace `var' =. if `var' == 9999
}

foreach var of varlist  labLookAfterMCW10 labLookAfterMCW12 labLookAfterMCW19 labLookAfterMCW20 labLookAfterMCW21 {
        replace `var' =. if `var' == 9999
}

foreach var of varlist  labLookAfterWCW10 labLookAfterWCW12 labLookAfterWCW19 labLookAfterWCW20 labLookAfterWCW21 {
        replace `var' =. if `var' == 9999
}
	
	
	
gen labLookAfterMCvWCW10 =.
label variable labLookAfterMCvWCW10 "Who does Lab rep better: the WC or the MC? (-3 to +3, Higher = MC)"
replace labLookAfterMCvWCW10 = labLookAfterMCW10 - labLookAfterWCW10
recode  labLookAfterMCvWCW10 (-3 = -3) (-2 = -2) (-1 = -1) (0=0) (1 = 1) (2 = 2) (3 = 3) (else=.)

gen labLookAfterBAWvWCW10 =.
label variable labLookAfterBAWvWCW10 "Who does Lab rep better: the WC or blacks and Asians? (-3 to +3, Higher = BAW)"
replace labLookAfterBAWvWCW10 = labLookAfterBAW10 - labLookAfterWCW10
recode labLookAfterBAWvWCW10 (-3 = -3) (-2 = -2) (-1 = -1) (0=0) (1 = 1) (2 = 2) (3 = 3) (else=.)
 
 
	 * Rescale so run 0-3
replace labLookAfterWCW10 = labLookAfterWCW10 - 1
replace labLookAfterBAW10 = labLookAfterBAW10 - 1	
replace labLookAfterMCW10 = labLookAfterMCW10 - 1


	
label define nulab 0 "Not at all closely" 1 "Not very closely" 2 "Fairly closely" 3 "Very closely", replace
label values labLookAfterBAW10 labLookAfterBAW19 labLookAfterBAW20 labLookAfterBAW21 labLookAfterMCW10 labLookAfterMCW12 labLookAfterMCW19 labLookAfterMCW20 labLookAfterMCW21 labLookAfterWCW10 labLookAfterWCW12 labLookAfterWCW19 labLookAfterWCW20 labLookAfterWCW21  nulab		
	
label define classbias_1 -3 "Working Class Bias" 0 "Equal" 3 "Middle Class Bias", replace
label define classbias_2 -3 "WC Bias" 0 "Equal" 3 "BME Bias", replace

label values labLookAfterMCvWCW* classbias_1
label values labLookAfterBAWvWCW* classbias_2

	

gen voteW10 =.
label variable voteW10 "Vote Intention W10 (Dec 2016)"	 
label define voteW10 0 "Non-Voter" 1 "Conservative" 2 "Labour" 3 "LibDem" 4 "SNP" 5 "Plaid Cymru" 6 "UKIP/BP" 7 "Greens" 8 "Change-UK" 9 "Other", replace 
label values voteW10 voteW10
	 
replace voteW10 = 0 if generalElectionVoteW10 == 0 
replace voteW10 = 1 if generalElectionVoteW10 == 1	 
replace voteW10 = 2 if generalElectionVoteW10 == 2	 	 
replace voteW10 = 3 if generalElectionVoteW10 == 3	 	 
replace voteW10 = 4 if generalElectionVoteW10 == 4	 	 
replace voteW10 = 5 if generalElectionVoteW10 == 5	 	 
replace voteW10 = 6 if generalElectionVoteW10 == 6	 	 
replace voteW10 = 7 if generalElectionVoteW10 == 7	 	 		 
replace voteW10 = 9 if generalElectionVoteW10 == 9			 
 
gen voteLabW10 =.
label var voteLabW10 "Would Vote Labour v Other W10 (Dec 2016)"
label define voteLabW10 1 "Labour" 0 "Other"
label values voteLabW10 voteLabW10 	 
	 
replace voteLabW10 = 1 if voteW10 == 2
replace voteLabW10 = 0 if voteW10 == 1 | inrange(voteW10,3,12)
	 

	
gen labIDstrengthW10 = .
label var labIDstrengthW10 "Strength of Labour Party Identification W10"
label define labIDstrengthW10 0 "No Labour ID" 1 "Not Very Strong Labour ID" 2 "Fairly Strong Labour ID" 3 "Very Strong Labour ID"
label values labIDstrengthW10  	labIDstrengthW10 
	
replace labIDstrengthW10 = 0 if partyIdW10 == 1 | inrange(partyIdW10,3,12)
replace labIDstrengthW10 = 1 if partyIdW10 == 2  & partyIdStrengthW10 == 3
replace labIDstrengthW10 = 2 if partyIdW10 == 2  & partyIdStrengthW10 == 2
replace labIDstrengthW10 = 3 if partyIdW10 == 2  & partyIdStrengthW10 == 1	
	
replace labIDstrengthW10 = 0 if labIDstrengthW10 ==. &  partyIdSqueezeW10 == 1 | labIDstrengthW10 ==. &  inrange(partyIdSqueezeW10,3,12)
replace labIDstrengthW10 = 1 if labIDstrengthW10 ==. &  partyIdSqueezeW10 == 2  & partyIdStrengthW10 == 3
replace labIDstrengthW10 = 2 if labIDstrengthW10 ==. &  partyIdSqueezeW10 == 2  & partyIdStrengthW10 == 2
replace labIDstrengthW10 = 3 if labIDstrengthW10 ==. &  partyIdSqueezeW10 == 2  & partyIdStrengthW10 == 1		 
	 
	 
	 
	 
	 
keep id wt_new_W10 objectiveclassW10 degreeW10 ethnicityW10 UKcountryW10 female agegrpW10 warmBMEW11 ethnocentrismw11 labLookAfterMCvWCW10 labLookAfterBAWvWCW10 voteW10 voteLabW10 ClassGroup_W10  lr_scaleW10_W12 al_scaleW10_W12 labLookAfterWCW10 labLookAfterBAW10 labLookAfterMCW10  labIDstrengthW10

rename wt_new_W10 WEIGHT
rename objectiveclassW10 OCCUPATION
rename degreeW10 DEGREE
rename ethnicityW10 RACE
rename ClassGroup_W10 GROUP
rename lr_scaleW10_W12 VALUES_LR
rename al_scaleW10_W12 VALUES_AL
rename UKcountryW10 COUNTRY
rename female FEMALE
rename agegrpW10 AGEGROUP
rename warmBMEW11 WARM_BME
rename ethnocentrismw11 ETHNOCENTRISM
rename labLookAfterWCW10 LAB_WC
rename labLookAfterBAW10 LAB_BME
rename labLookAfterMCW10 LAB_MC
rename labLookAfterMCvWCW10 LAB_MCoverWC
rename labLookAfterBAWvWCW10 LAB_BMEoverWC
rename labIDstrengthW10 LABOUR_ID
rename voteW10 VOTE_long
rename voteLabW10 VOTE_LAB
rename id BES_id

gen WAVE = 10
gen MERGE_ID = _n //* Last one 30237

save "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\Wave10.dta", replace
clear





	  
********** WAVE 19 (2019) VARIABLE CONSTRUCTION
	 
use "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\BES2019_W21_Panel_v21.0.dta", clear //* BESIP Panel, Combined Wave 1-21 Internet Panel (2021 Release) - Later editions should also work fine 
	

drop if wave19 != 1	 

gen objectiveclassW19 =.
label define objectiveclassW19 1 "Old Middle Class" 2 "New Middle Class" 3 "Intermediate Class" 4 "Own Account" 5 "Foremen + Supervisors" 6 "Working Class" 7 "Other Outside Labour Force", replace
label variable objectiveclassW19 "Respondent Occupational Class"
label values objectiveclassW19 objectiveclassW19

replace objectiveclassW19 = 1 if inlist(ns_secW19,10,20,33,34,43,50,81,82,92) 
replace objectiveclassW19 = 2 if inlist(ns_secW19,31,32,41,42,60)   
replace objectiveclassW19 = 3 if inlist(ns_secW19,71,72,73,74) 
replace objectiveclassW19 = 4 if inlist(ns_secW19,44,91) 
replace objectiveclassW19 = 5 if inlist(ns_secW19,100)  
replace objectiveclassW19 = 6 if inrange(ns_secW19,111,135) 

replace objectiveclassW19 = 1 if inrange(selfNumEmployeesLastW19,1,9999) //* Assign employers to top category

replace objectiveclassW19 = 1 if selfOccStatusW19 == 0 & inlist(objectiveclassW19,2) //* Assign self-employed professionals to top category
replace objectiveclassW19 = 1 if selfOccStatusLastW19 == 0 & inlist(objectiveclassW19,2)

replace objectiveclassW19 = 4 if selfOccStatusW19 == 0 & inlist(objectiveclassW19,3,4,5,6,7)  //* Assign lower self-employed to own account
replace objectiveclassW19 = 4 if selfOccStatusLastW19 == 0 & inlist(objectiveclassW19,3,4,5,6,7)

replace objectiveclassW19 = 7 if ns_secW19 ==. & inlist(workingStatusW19,4,5,6,7,8) //* Assign those without social class information to an additional category



gen degreeW19 =.
label define degreeW19 1 "University Degree or at Uni now" 0 "No University Degree"
label var    degreeW19   "Dummy: Has a University Degree or Equivalent, or is Currently at Uni"
label values degreeW19 degreeW19
replace degreeW19 = 1 if inlist(p_educationW19,13,14,15,16,17)
replace degreeW19 = 0 if degreeW19 != 1 & p_educationW19 !=. & p_educationW19 != 20



gen ethnicityW19 =.
label define ethnicityW19 1 "White" 2 "Non-White / Mixed", replace
label variable ethnicityW19 "Respondent Ethnicity"
label values ethnicityW19 ethnicityW19 

replace ethnicityW19 = 1 if inlist(p_ethnicityW19,1,2) | ethnicityW19 == . & inlist(p_ethnicityW18,1,2)
replace ethnicityW19 = 2 if inrange(p_ethnicityW19,3,15) | ethnicityW19 == . & inlist(p_ethnicityW18,3,15)


gen whites_allclassesW19 =.
label var whites_allclassesW19 "Occupational Class (All White Respondents)"
label define whites_allclassesW19 1 "Old Middle Class" 2 "New Middle Class" 3 "Intermediate Class" 4 "Own Account" 5 "Foremen + Supervisors" 6 "Working Class" 7 "Unidentified / Out of Labour Market" 99 "Ethnic Minority", replace
label values whites_allclassesW19 whites_allclassesW19

replace whites_allclassesW19 = 1 if objectiveclassW19 == 1 & ethnicityW19 == 1
replace whites_allclassesW19 = 2 if objectiveclassW19 == 2 & ethnicityW19 == 1
replace whites_allclassesW19 = 3 if objectiveclassW19 == 3 & ethnicityW19 == 1
replace whites_allclassesW19 = 4 if objectiveclassW19 == 4 & ethnicityW19 == 1
replace whites_allclassesW19 = 5 if objectiveclassW19 == 5 & ethnicityW19 == 1
replace whites_allclassesW19 = 6 if objectiveclassW19 == 6 & ethnicityW19 == 1
replace whites_allclassesW19 = 7 if objectiveclassW19 == 7 & ethnicityW19 == 1
replace whites_allclassesW19 = 99 if ethnicityW19 == 2


gen ClassGroup_W19 =.
label define ClassGroup_W19 1 "White Working Class" 2 "White Graduates" 3 "Other Whites" 4 "Ethnic Minorities", replace
label values ClassGroup_W19 ClassGroup_W19

replace ClassGroup_W19 = 1 if whites_allclassesW19 == 6 & ethnicityW19 == 1 & degreeW19 == 0
replace ClassGroup_W19 = 2 if whites_allclassesW19 !=.  & ethnicityW19 == 1 & degreeW19 == 1
replace ClassGroup_W19 = 3 if ClassGroup_W19 ==.        & ethnicityW19 == 1 & degreeW19 != .
replace ClassGroup_W19 = 4 if ClassGroup_W19 ==.        & ethnicityW19 == 2 & degreeW19 != . 





gen UKcountryW19 =.
label variable UKcountryW19 "Constituent UK Country (W19 or Other Most Current)"
label define countryW19 1 "England" 2 "Wales" 3 "Scotland"
label values UKcountryW19 countryW19

replace UKcountryW19 = 1 if countryW19 == 1
replace UKcountryW19 = 2 if countryW19 == 3
replace UKcountryW19 = 3 if countryW19 == 2



* Female
gen female =.
replace female = 1 if gender == 2
replace female = 0 if gender == 1

rename Age age


gen agegrpW19 =.
label variable agegrpW19 "Age (4 Groups)"
label define agegrpW19 1 "18-25" 2 "26-44" 3 "45-64" 4 "65+"
label values agegrpW19 agegrpW19

replace agegrpW19 = 1 if inrange(ageW19,16,25)
replace agegrpW19 = 2 if inrange(ageW19,26,44)
replace agegrpW19 = 3 if inrange(ageW19,45,64)
replace agegrpW19 = 4 if inrange(ageW19,65,120)




* Ethnocentrism

order warmWhiteW11 warmAsianW11 warmBlackW11 warmWCW11 warmMCW11, after(partyIdSqueezeW21)

foreach var of varlist warmWhiteW11 -  warmMCW11 {
        replace `var' =. if `var' == 9999
}


gen warmBMEW11 = (warmAsianW11 + warmBlackW11)/2

gen ethnocentrismw11 = (warmWhiteW11 - warmBMEW11) / 10
label var ethnocentrismw11 "Respondent White Ethnocentrism (How Much More likes Whites than BME)"
label define ethno -10 "Wholly BMEcentric" 0 "Neutral" 10 "Wholly Whitecentric", replace
	 
		 
		

* Group Representation	

foreach var of varlist  labLookAfterBAW10 labLookAfterBAW19 labLookAfterBAW20 labLookAfterBAW21 {
        replace `var' =. if `var' == 9999
}

foreach var of varlist  labLookAfterMCW10 labLookAfterMCW12 labLookAfterMCW19 labLookAfterMCW20 labLookAfterMCW21 {
        replace `var' =. if `var' == 9999
}

foreach var of varlist  labLookAfterWCW10 labLookAfterWCW12 labLookAfterWCW19 labLookAfterWCW20 labLookAfterWCW21 {
        replace `var' =. if `var' == 9999
}
	
	
	
gen labLookAfterMCvWCW19 =.
label variable labLookAfterMCvWCW19 "Who does Lab rep better: the WC or the MC? (-3 to +3, Higher = MC)"
replace labLookAfterMCvWCW19 = labLookAfterMCW19 - labLookAfterWCW19
recode  labLookAfterMCvWCW19 (-3 = -3) (-2 = -2) (-1 = -1) (0=0) (1 = 1) (2 = 2) (3 = 3) (else=.)

gen labLookAfterBAWvWCW19 =.
label variable labLookAfterBAWvWCW19 "Who does Lab rep better: the WC or blacks and Asians? (-3 to +3, Higher = BAW)"
replace labLookAfterBAWvWCW19 = labLookAfterBAW19 - labLookAfterWCW19
recode labLookAfterBAWvWCW19 (-3 = -3) (-2 = -2) (-1 = -1) (0=0) (1 = 1) (2 = 2) (3 = 3) (else=.)
 
 
	 
replace labLookAfterWCW19 = labLookAfterWCW19 - 1
replace labLookAfterBAW19 = labLookAfterBAW19 - 1	
replace labLookAfterMCW19 = labLookAfterMCW19 - 1


	
label define nulab 0 "Not at all closely" 1 "Not very closely" 2 "Fairly closely" 3 "Very closely", replace
label values labLookAfterBAW10 labLookAfterBAW19 labLookAfterBAW20 labLookAfterBAW21 labLookAfterMCW10 labLookAfterMCW12 labLookAfterMCW19 labLookAfterMCW20 labLookAfterMCW21 labLookAfterWCW10 labLookAfterWCW12 labLookAfterWCW19 labLookAfterWCW20 labLookAfterWCW21  nulab		
	
label define classbias_1 -3 "Working Class Bias" 0 "Equal" 3 "Middle Class Bias", replace
label define classbias_2 -3 "WC Bias" 0 "Equal" 3 "BME Bias", replace

label values labLookAfterMCvWCW* classbias_1
label values labLookAfterBAWvWCW* classbias_2

gen labIDstrengthW19 = .
label var labIDstrengthW19 "Strength of Labour Party Identification W19"
label define labIDstrengthW19 0 "No Labour ID" 1 "Not Very Strong Labour ID" 2 "Fairly Strong Labour ID" 3 "Very Strong Labour ID"
label values labIDstrengthW19  	labIDstrengthW19 
	
replace labIDstrengthW19 = 0 if partyIdW19 == 1 | inrange(partyIdW19,3,12)
replace labIDstrengthW19 = 1 if partyIdW19 == 2  & partyIdStrengthW19 == 3
replace labIDstrengthW19 = 2 if partyIdW19 == 2  & partyIdStrengthW19 == 2
replace labIDstrengthW19 = 3 if partyIdW19 == 2  & partyIdStrengthW19 == 1	
	
replace labIDstrengthW19 = 0 if labIDstrengthW19 ==. &  partyIdSqueezeW19 == 1 | labIDstrengthW19 ==. &  inrange(partyIdSqueezeW19,3,12)
replace labIDstrengthW19 = 1 if labIDstrengthW19 ==. &  partyIdSqueezeW19 == 2  & partyIdStrengthW19 == 3
replace labIDstrengthW19 = 2 if labIDstrengthW19 ==. &  partyIdSqueezeW19 == 2  & partyIdStrengthW19 == 2
replace labIDstrengthW19 = 3 if labIDstrengthW19 ==. &  partyIdSqueezeW19 == 2  & partyIdStrengthW19 == 1	
	
			
		
gen voteW19 =.
label variable voteW19 "Vote 2019 Election"	 
label define voteW19 0 "Non-Voter" 1 "Conservative" 2 "Labour" 3 "LibDem" 4 "SNP" 5 "Plaid Cymru" 6 "UKIP/BP/Reform" 7 "Greens" 8 "Change-UK" 9 "Other", replace 
label values voteW19 voteW19
	 
replace voteW19 = 0 if genElecTurnoutRetroW19 == 0 
replace voteW19 = 1 if generalElectionVoteW19 == 1	 
replace voteW19 = 2 if generalElectionVoteW19 == 2	 	 
replace voteW19 = 3 if generalElectionVoteW19 == 3	 	 
replace voteW19 = 4 if generalElectionVoteW19 == 4	 	 
replace voteW19 = 5 if generalElectionVoteW19 == 5	 	 
replace voteW19 = 6 if generalElectionVoteW19 == 6 | generalElectionVoteW19 == 12	 	 
replace voteW19 = 7 if generalElectionVoteW19 == 7	 
replace voteW19 = 8 if generalElectionVoteW19 == 8	
replace voteW19 = 9 if generalElectionVoteW19 == 9 | generalElectionVoteW19 == 13		 	 
	
	 
gen voteLabW19 =.
label var voteLabW19 "Voted Labour v Other W19 (Dec 2019 Election)"
label define voteLabW19 1 "Labour" 0 "Other"
label values voteLabW19 voteLabW19 	 
	 
replace voteLabW19 = 1 if voteW19 == 2
replace voteLabW19 = 0 if voteW19 == 1 | inrange(voteW19,3,12)	 
	 	
		

keep id wt_new_W19_result objectiveclassW19 degreeW19 ethnicityW19 ClassGroup_W19 UKcountryW19 female agegrpW19 warmBMEW11 ethnocentrismw11 labLookAfterMCvWCW19 labLookAfterBAWvWCW19 voteW19 voteLabW19 lr_scaleW17 al_scaleW17 labLookAfterWCW19 labLookAfterBAW19 labLookAfterMCW19 labIDstrengthW19

rename id BES_id
rename wt_new_W19_result WEIGHT
rename objectiveclassW19 OCCUPATION
rename degreeW19 DEGREE
rename ethnicityW19 RACE
rename ClassGroup_W19 GROUP
rename lr_scaleW17 VALUES_LR
rename al_scaleW17 VALUES_AL
rename UKcountryW19 COUNTRY
rename female FEMALE
rename agegrpW19 AGEGROUP
rename warmBMEW11 WARM_BME
rename ethnocentrismw11 ETHNOCENTRISM
rename labLookAfterWCW19 LAB_WC
rename labLookAfterBAW19 LAB_BME
rename labLookAfterMCW19 LAB_MC
rename labLookAfterMCvWCW19 LAB_MCoverWC
rename labLookAfterBAWvWCW19 LAB_BMEoverWC
rename voteW19 VOTE_long
rename voteLabW19 VOTE_LAB
rename labIDstrengthW19 LABOUR_ID

gen WAVE = 19
gen MERGE_ID = _n + 30237 //* Last one 62414
save "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\Wave19.dta", replace
clear

****************************

	  
********** WAVE 20 (2020) VARIABLE CONSTRUCTION
	 
use "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\BES2019_W21_Panel_v21.0.dta", clear //* BESIP Panel, Combined Wave 1-21 Internet Panel (2021 Release) - Later editions should also work fine 
	

drop if wave20 != 1	 


gen objectiveclassW20 =.
label define objectiveclassW20 1 "Old Middle Class" 2 "New Middle Class" 3 "Intermediate Class" 4 "Own Account" 5 "Foremen + Supervisors" 6 "Working Class" 7 "Other Outside Labour Force", replace
label variable objectiveclassW20 "Respondent Occupational Class"
label values objectiveclassW20 objectiveclassW20

replace objectiveclassW20 = 1 if inlist(ns_secW20,10,20,33,34,43,50,81,82,92) 
replace objectiveclassW20 = 2 if inlist(ns_secW20,31,32,41,42,60)   
replace objectiveclassW20 = 3 if inlist(ns_secW20,71,72,73,74) 
replace objectiveclassW20 = 4 if inlist(ns_secW20,44,91) 
replace objectiveclassW20 = 5 if inlist(ns_secW20,100)  
replace objectiveclassW20 = 6 if inrange(ns_secW20,111,135) 

replace objectiveclassW20 = 1 if inrange(selfNumEmployeesLastW20,1,9999) //* Assign employers to top category

replace objectiveclassW20 = 1 if selfOccStatusW20 == 0 & inlist(objectiveclassW20,2) //* Assign self-employed professionals to top category
replace objectiveclassW20 = 1 if selfOccStatusLastW20 == 0 & inlist(objectiveclassW20,2)

replace objectiveclassW20 = 4 if selfOccStatusW20 == 0 & inlist(objectiveclassW20,3,4,5,6,7)  //* Assign lower self-employed to own account
replace objectiveclassW20 = 4 if selfOccStatusLastW20 == 0 & inlist(objectiveclassW20,3,4,5,6,7)

replace objectiveclassW20 = 7 if ns_secW20 ==. & inlist(workingStatusW20,4,5,6,7,8) //* Assign those without social class information to an additional category




gen degreeW20 =.
label define degreeW20 1 "University Degree or at Uni now" 0 "No University Degree"
label var    degreeW20   "Dummy: Has a University Degree or Equivalent, or is Currently at Uni"
label values degreeW20 degreeW20
replace degreeW20 = 1 if inlist(p_educationW20,13,14,15,16,17)
replace degreeW20 = 0 if degreeW20 != 1 & p_educationW20 !=. & p_educationW20 != 20



gen ethnicityW20 =.
label define ethnicityW20 1 "White" 2 "Non-White / Mixed", replace
label variable ethnicityW20 "Respondent Ethnicity"
label values ethnicityW20 ethnicityW20 

replace ethnicityW20 = 1 if inlist(p_ethnicityW20,1,2)  
replace ethnicityW20 = 2 if inrange(p_ethnicityW20,3,15) 


gen whites_allclassesW20 =.
label var whites_allclassesW20 "Occupational Class (All White Respondents)"
label define whites_allclassesW20 1 "Old Middle Class" 2 "New Middle Class" 3 "Intermediate Class" 4 "Own Account" 5 "Foremen + Supervisors" 6 "Working Class" 7 "Unidentified / Out of Labour Market" 99 "Ethnic Minority", replace
label values whites_allclassesW20 whites_allclassesW20

replace whites_allclassesW20 = 1 if objectiveclassW20 == 1 & ethnicityW20 == 1
replace whites_allclassesW20 = 2 if objectiveclassW20 == 2 & ethnicityW20 == 1
replace whites_allclassesW20 = 3 if objectiveclassW20 == 3 & ethnicityW20 == 1
replace whites_allclassesW20 = 4 if objectiveclassW20 == 4 & ethnicityW20 == 1
replace whites_allclassesW20 = 5 if objectiveclassW20 == 5 & ethnicityW20 == 1
replace whites_allclassesW20 = 6 if objectiveclassW20 == 6 & ethnicityW20 == 1
replace whites_allclassesW20 = 7 if objectiveclassW20 == 7 & ethnicityW20 == 1
replace whites_allclassesW20 = 99 if ethnicityW20 == 2



gen ClassGroup_W20 =.
label define ClassGroup_W20 1 "White Working Class" 2 "White Graduates" 3 "Other Whites" 4 "Ethnic Minorities", replace
label values ClassGroup_W20 ClassGroup_W20

replace ClassGroup_W20 = 1 if whites_allclassesW20 == 6 & ethnicityW20 == 1 & degreeW20 == 0
replace ClassGroup_W20 = 2 if whites_allclassesW20 !=.  & ethnicityW20 == 1 & degreeW20 == 1
replace ClassGroup_W20 = 3 if ClassGroup_W20 ==.        & ethnicityW20 == 1 & degreeW20 != .
replace ClassGroup_W20 = 4 if ClassGroup_W20 ==.        & ethnicityW20 == 2 & degreeW20 != . 



gen UKcountryW20 =.
label variable UKcountryW20 "Constituent UK Country (W19 or Other Most Current)"
label define countryW20 1 "England" 2 "Wales" 3 "Scotland"
label values UKcountryW20 countryW20

replace UKcountryW20 = 1 if countryW20 == 1
replace UKcountryW20 = 2 if countryW20 == 3
replace UKcountryW20 = 3 if countryW20 == 2



* Female
gen female =.
replace female = 1 if gender == 2
replace female = 0 if gender == 1

rename Age age


gen agegrpW20 =.
label variable agegrpW20 "Age (4 Groups)"
label define agegrpW20 1 "18-25" 2 "26-44" 3 "45-64" 4 "65+"
label values agegrpW20 agegrpW20

replace agegrpW20 = 1 if inrange(ageW20,16,25)
replace agegrpW20 = 2 if inrange(ageW20,26,44)
replace agegrpW20 = 3 if inrange(ageW20,45,64)
replace agegrpW20 = 4 if inrange(ageW20,65,120)

		
		
gen voteW20 =.
label variable voteW20 "Vote 2019 Election"	 
label define voteW20 0 "Non-Voter" 1 "Conservative" 2 "Labour" 3 "LibDem" 4 "SNP" 5 "Plaid Cymru" 6 "UKIP/BP/Reform" 7 "Greens" 8 "Change-UK" 9 "Other", replace 
label values voteW20 voteW20
	 
replace voteW20 = 0 if generalElectionVoteW20 == 0 
replace voteW20 = 1 if generalElectionVoteW20 == 1	 
replace voteW20 = 2 if generalElectionVoteW20 == 2	 	 
replace voteW20 = 3 if generalElectionVoteW20 == 3	 	 
replace voteW20 = 4 if generalElectionVoteW20 == 4	 	 
replace voteW20 = 5 if generalElectionVoteW20 == 5	 	 
replace voteW20 = 6 if generalElectionVoteW20 == 6 | generalElectionVoteW20 == 12	 	 
replace voteW20 = 7 if generalElectionVoteW20 == 7	 
replace voteW20 = 8 if generalElectionVoteW20 == 8	
replace voteW20 = 9 if generalElectionVoteW20 == 9 | generalElectionVoteW20 == 13		 	 
	
	 
gen voteLabW20 =.
label var voteLabW20 "Voted Labour v Other W20 (Dec 2019 Election)"
label define voteLabW20 1 "Labour" 0 "Other"
label values voteLabW20 voteLabW20 	 
	 
replace voteLabW20 = 1 if voteW20 == 2
replace voteLabW20 = 0 if voteW20 == 1 | inrange(voteW20,3,12)	 


gen labIDstrengthW20 = .
label var labIDstrengthW20 "Strength of Labour Party Identification W20"
label define labIDstrengthW20 0 "No Labour ID" 1 "Not Very Strong Labour ID" 2 "Fairly Strong Labour ID" 3 "Very Strong Labour ID"
label values labIDstrengthW20  	labIDstrengthW20 
	
replace labIDstrengthW20 = 0 if partyIdW20 == 1 | inrange(partyIdW20,3,12)
replace labIDstrengthW20 = 1 if partyIdW20 == 2  & partyIdStrengthW20 == 3
replace labIDstrengthW20 = 2 if partyIdW20 == 2  & partyIdStrengthW20 == 2
replace labIDstrengthW20 = 3 if partyIdW20 == 2  & partyIdStrengthW20 == 1	
	
replace labIDstrengthW20 = 0 if labIDstrengthW20 ==. &  partyIdSqueezeW20 == 1 | labIDstrengthW20 ==. &  inrange(partyIdSqueezeW20,3,12)
replace labIDstrengthW20 = 1 if labIDstrengthW20 ==. &  partyIdSqueezeW20 == 2  & partyIdStrengthW20 == 3
replace labIDstrengthW20 = 2 if labIDstrengthW20 ==. &  partyIdSqueezeW20 == 2  & partyIdStrengthW20 == 2
replace labIDstrengthW20 = 3 if labIDstrengthW20 ==. &  partyIdSqueezeW20 == 2  & partyIdStrengthW20 == 1	
	
	
* Ethnocentrism

order warmWhiteW11 warmAsianW11 warmBlackW11 warmWCW11 warmMCW11, after(partyIdSqueezeW21)

foreach var of varlist warmWhiteW11 -  warmMCW11 {
        replace `var' =. if `var' == 9999
}


gen warmBMEW11 = (warmAsianW11 + warmBlackW11)/2

gen ethnocentrismw11 = (warmWhiteW11 - warmBMEW11) / 10
label var ethnocentrismw11 "Respondent White Ethnocentrism (How Much More likes Whites than BME)"
label define ethno -10 "Wholly BMEcentric" 0 "Neutral" 10 "Wholly Whitecentric", replace
	 
		 
		

* Group Representation	

foreach var of varlist  labLookAfterBAW10 labLookAfterBAW19 labLookAfterBAW20 labLookAfterBAW21 {
        replace `var' =. if `var' == 9999
}

foreach var of varlist  labLookAfterMCW10 labLookAfterMCW12 labLookAfterMCW19 labLookAfterMCW20 labLookAfterMCW21 {
        replace `var' =. if `var' == 9999
}

foreach var of varlist  labLookAfterWCW10 labLookAfterWCW12 labLookAfterWCW19 labLookAfterWCW20 labLookAfterWCW21 {
        replace `var' =. if `var' == 9999
}
	
	
	
 
gen labLookAfterMCvWCW20 =.
label variable labLookAfterMCvWCW20 "Who does Lab rep better: the WC or the MC? (-3 to +3, Higher = MC)"
replace labLookAfterMCvWCW20 = labLookAfterMCW20 - labLookAfterWCW20
recode  labLookAfterMCvWCW20 (-3 = -3) (-2 = -2) (-1 = -1) (0=0) (1 = 1) (2 = 2) (3 = 3) (else=.)

gen labLookAfterBAWvWCW20 =.
label variable labLookAfterBAWvWCW20 "Who does Lab rep better: the WC or blacks and Asians? (-3 to +3, Higher = BAW)"
replace labLookAfterBAWvWCW20 = labLookAfterBAW20 - labLookAfterWCW20
recode labLookAfterBAWvWCW20 (-3 = -3) (-2 = -2) (-1 = -1) (0=0) (1 = 1) (2 = 2) (3 = 3) (else=.)
 
 
	 
replace labLookAfterWCW20 = labLookAfterWCW20 - 1
replace labLookAfterBAW20 = labLookAfterBAW20 - 1	
replace labLookAfterMCW20 = labLookAfterMCW20 - 1


	
label define nulab 0 "Not at all closely" 1 "Not very closely" 2 "Fairly closely" 3 "Very closely", replace
label values labLookAfterBAW10 labLookAfterBAW19 labLookAfterBAW20 labLookAfterBAW21 labLookAfterMCW10 labLookAfterMCW12 labLookAfterMCW19 labLookAfterMCW20 labLookAfterMCW21 labLookAfterWCW10 labLookAfterWCW12 labLookAfterWCW19 labLookAfterWCW20 labLookAfterWCW21  nulab		
	
label define classbias_1 -3 "Working Class Bias" 0 "Equal" 3 "Middle Class Bias", replace
label define classbias_2 -3 "WC Bias" 0 "Equal" 3 "BME Bias", replace

label values labLookAfterMCvWCW* classbias_1
label values labLookAfterBAWvWCW* classbias_2


keep id wt_new_W20 objectiveclassW20 degreeW20 ethnicityW20 ClassGroup_W20 UKcountryW20 female agegrpW20 warmBMEW11 ethnocentrismw11 labLookAfterMCvWCW20 labLookAfterBAWvWCW20 voteW20 voteLabW20 lr_scaleW20 al_scaleW20 labLookAfterWCW20 labLookAfterBAW20 labLookAfterMCW20 labIDstrengthW20

rename id BES_id
rename wt_new_W20 WEIGHT
rename objectiveclassW20 OCCUPATION
rename degreeW20 DEGREE
rename ethnicityW20 RACE
rename ClassGroup_W20 GROUP
rename lr_scaleW20 VALUES_LR
rename al_scaleW20 VALUES_AL
rename UKcountryW20 COUNTRY
rename female FEMALE
rename agegrpW20 AGEGROUP
rename warmBMEW11 WARM_BME
rename ethnocentrismw11 ETHNOCENTRISM
rename labLookAfterWCW20 LAB_WC
rename labLookAfterBAW20 LAB_BME
rename labLookAfterMCW20 LAB_MC
rename labLookAfterMCvWCW20 LAB_MCoverWC
rename labLookAfterBAWvWCW20 LAB_BMEoverWC
rename voteW20 VOTE_long
rename voteLabW20 VOTE_LAB
rename labIDstrengthW20 LABOUR_ID

gen WAVE = 20
gen MERGE_ID = _n + 62414 //* Last one 93882

save "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\Wave20.dta", replace
clear
	  
********** WAVE 21 (2021) VARIABLE CONSTRUCTION
	 
use "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\BES2019_W21_Panel_v21.0.dta", clear //* BESIP Panel, Combined Wave 1-21 Internet Panel (2021 Release) - Later editions should also work fine 
	 	 
		 
drop if wave21 != 1	 



gen objectiveclassW21 =.
label define objectiveclassW21 1 "Old Middle Class" 2 "New Middle Class" 3 "Intermediate Class" 4 "Own Account" 5 "Foremen + Supervisors" 6 "Working Class" 7 "Other Outside Labour Force", replace
label variable objectiveclassW21 "Respondent Occupational Class"
label values objectiveclassW21 objectiveclassW21

replace objectiveclassW21 = 1 if inlist(ns_secW21,10,20,33,34,43,50,81,82,92) 
replace objectiveclassW21 = 2 if inlist(ns_secW21,31,32,41,42,60)   
replace objectiveclassW21 = 3 if inlist(ns_secW21,71,72,73,74) 
replace objectiveclassW21 = 4 if inlist(ns_secW21,44,91) 
replace objectiveclassW21 = 5 if inlist(ns_secW21,100)  
replace objectiveclassW21 = 6 if inrange(ns_secW21,111,135) 

replace objectiveclassW21 = 1 if inrange(selfNumEmployeesLastW21,1,9999) //* Assign employers to top category

replace objectiveclassW21 = 1 if selfOccStatusW21 == 0 & inlist(objectiveclassW21,2) //* Assign self-employed professionals to top category
replace objectiveclassW21 = 1 if selfOccStatusLastW21 == 0 & inlist(objectiveclassW21,2)

replace objectiveclassW21 = 4 if selfOccStatusW21 == 0 & inlist(objectiveclassW21,3,4,5,6,7)  //* Assign lower self-employed to own account
replace objectiveclassW21 = 4 if selfOccStatusLastW21 == 0 & inlist(objectiveclassW21,3,4,5,6,7)

replace objectiveclassW21 = 7 if ns_secW21 ==. & inlist(workingStatusW21,4,5,6,7,8) //* Assign those without social class information to an additional category



gen degreeW21 =.
label define degreeW21 1 "University Degree or at Uni now" 0 "No University Degree"
label var    degreeW21   "Dummy: Has a University Degree or Equivalent, or is Currently at Uni"
label values degreeW21 degreeW21
replace degreeW21 = 1 if inlist(p_educationW21,13,14,15,16,17)
replace degreeW21 = 0 if degreeW21 != 1 & p_educationW21 !=. & p_educationW21 != 20



gen ethnicityW21 =.
label define ethnicityW21 1 "White" 2 "Non-White / Mixed", replace
label variable ethnicityW21 "Respondent Ethnicity"
label values ethnicityW21 ethnicityW21 

replace ethnicityW21 = 1 if inlist(p_ethnicityW21,1,2)   
replace ethnicityW21 = 2 if inrange(p_ethnicityW21,3,15) 



gen whites_allclassesW21 =.
label var whites_allclassesW21 "Occupational Class (All White Respondents)"
label define whites_allclassesW21 1 "Old Middle Class" 2 "New Middle Class" 3 "Intermediate Class" 4 "Own Account" 5 "Foremen + Supervisors" 6 "Working Class" 7 "Unidentified / Out of Labour Market" 99 "Ethnic Minority", replace
label values whites_allclassesW21 whites_allclassesW21

replace whites_allclassesW21 = 1 if objectiveclassW21 == 1 & ethnicityW21 == 1
replace whites_allclassesW21 = 2 if objectiveclassW21 == 2 & ethnicityW21 == 1
replace whites_allclassesW21 = 3 if objectiveclassW21 == 3 & ethnicityW21 == 1
replace whites_allclassesW21 = 4 if objectiveclassW21 == 4 & ethnicityW21 == 1
replace whites_allclassesW21 = 5 if objectiveclassW21 == 5 & ethnicityW21 == 1
replace whites_allclassesW21 = 6 if objectiveclassW21 == 6 & ethnicityW21 == 1
replace whites_allclassesW21 = 7 if objectiveclassW21 == 7 & ethnicityW21 == 1
replace whites_allclassesW21 = 99 if ethnicityW21 == 2


gen ClassGroup_W21 =.
label define ClassGroup_W21 1 "White Working Class" 2 "White Graduates" 3 "Other Whites" 4 "Ethnic Minorities", replace
label values ClassGroup_W21 ClassGroup_W21

replace ClassGroup_W21 = 1 if whites_allclassesW21 == 6 & ethnicityW21 == 1 & degreeW21 == 0
replace ClassGroup_W21 = 2 if whites_allclassesW21 !=.  & ethnicityW21 == 1 & degreeW21 == 1
replace ClassGroup_W21 = 3 if ClassGroup_W21 ==.        & ethnicityW21 == 1 & degreeW21 != .
replace ClassGroup_W21 = 4 if ClassGroup_W21 ==.        & ethnicityW21 == 2 & degreeW21 != . 



*** 



gen UKcountryW21 =.
label variable UKcountryW21 "Constituent UK Country (W19 or Other Most Current)"
label define countryW21 1 "England" 2 "Wales" 3 "Scotland"
label values UKcountryW21 countryW21

replace UKcountryW21 = 1 if countryW21 == 1
replace UKcountryW21 = 2 if countryW21 == 3
replace UKcountryW21 = 3 if countryW21 == 2



* Female
gen female =.
replace female = 1 if gender == 2
replace female = 0 if gender == 1

rename Age age



gen agegrpW21 =.
label variable agegrpW21 "Age (4 Groups)"
label define agegrpW21 1 "18-25" 2 "26-44" 3 "45-64" 4 "65+"
label values agegrpW21 agegrpW21

replace agegrpW21 = 1 if inrange(ageW21,16,25)
replace agegrpW21 = 2 if inrange(ageW21,26,44)
replace agegrpW21 = 3 if inrange(ageW21,45,64)
replace agegrpW21 = 4 if inrange(ageW21,65,120)

		
		
gen voteW21 =.
label variable voteW21 "Vote Intention W21 (June 2021)"	 
label define voteW21 0 "Non-Voter" 1 "Conservative" 2 "Labour" 3 "LibDem" 4 "SNP" 5 "Plaid Cymru" 6 "UKIP/BP/Reform" 7 "Greens" 8 "Change-UK" 9 "Other", replace 
label values voteW21 voteW21
	 
replace voteW21 = 0 if generalElectionVoteW21 == 0 
replace voteW21 = 1 if generalElectionVoteW21 == 1	 
replace voteW21 = 2 if generalElectionVoteW21 == 2	 	 
replace voteW21 = 3 if generalElectionVoteW21 == 3	 	 
replace voteW21 = 4 if generalElectionVoteW21 == 4	 	 
replace voteW21 = 5 if generalElectionVoteW21 == 5	 	 
replace voteW21 = 6 if generalElectionVoteW21 == 6 | generalElectionVoteW21 == 12	 	 
replace voteW21 = 7 if generalElectionVoteW21 == 7	 
replace voteW21 = 8 if generalElectionVoteW21 == 8	
replace voteW21 = 9 if generalElectionVoteW21 == 9 | generalElectionVoteW21 == 13				 
		 
	 
	 
gen voteLabW21 =.
label var voteLabW21 "Would Vote Labour v Other W21 (June 2021)"
label define voteLabW21 1 "Labour" 0 "Other"
label values voteLabW21 voteLabW21 	 
	 
replace voteLabW21 = 1 if voteW21 == 2
replace voteLabW21 = 0 if voteW21 == 1 | inrange(voteW21,3,12)



gen labIDstrengthW21 = .
label var labIDstrengthW21 "Strength of Labour Party Identification W21"
label define labIDstrengthW21 0 "No Labour ID" 1 "Not Very Strong Labour ID" 2 "Fairly Strong Labour ID" 3 "Very Strong Labour ID"
label values labIDstrengthW21  	labIDstrengthW21 
	
replace labIDstrengthW21 = 0 if partyIdW21 == 1 | inrange(partyIdW21,3,12)
replace labIDstrengthW21 = 1 if partyIdW21 == 2  & partyIdStrengthW21 == 3
replace labIDstrengthW21 = 2 if partyIdW21 == 2  & partyIdStrengthW21 == 2
replace labIDstrengthW21 = 3 if partyIdW21 == 2  & partyIdStrengthW21 == 1	
	
replace labIDstrengthW21 = 0 if labIDstrengthW21 ==. &  partyIdSqueezeW21 == 1 | labIDstrengthW21 ==. &  inrange(partyIdSqueezeW21,3,12)
replace labIDstrengthW21 = 1 if labIDstrengthW21 ==. &  partyIdSqueezeW21 == 2  & partyIdStrengthW21 == 3
replace labIDstrengthW21 = 2 if labIDstrengthW21 ==. &  partyIdSqueezeW21 == 2  & partyIdStrengthW21 == 2
replace labIDstrengthW21 = 3 if labIDstrengthW21 ==. &  partyIdSqueezeW21 == 2  & partyIdStrengthW21 == 1	
	

	
* Ethnocentrism

order warmWhiteW11 warmAsianW11 warmBlackW11 warmWCW11 warmMCW11, after(partyIdSqueezeW21)

foreach var of varlist warmWhiteW11 -  warmMCW11 {
        replace `var' =. if `var' == 9999
}


gen warmBMEW11 = (warmAsianW11 + warmBlackW11)/2

gen ethnocentrismw11 = (warmWhiteW11 - warmBMEW11) / 10
label var ethnocentrismw11 "Respondent White Ethnocentrism (How Much More likes Whites than BME)"
label define ethno -10 "Wholly BMEcentric" 0 "Neutral" 10 "Wholly Whitecentric", replace
	 
		 
		

* Group Representation	

foreach var of varlist  labLookAfterBAW10 labLookAfterBAW19 labLookAfterBAW20 labLookAfterBAW21 {
        replace `var' =. if `var' == 9999
}

foreach var of varlist  labLookAfterMCW10 labLookAfterMCW12 labLookAfterMCW19 labLookAfterMCW20 labLookAfterMCW21 {
        replace `var' =. if `var' == 9999
}

foreach var of varlist  labLookAfterWCW10 labLookAfterWCW12 labLookAfterWCW19 labLookAfterWCW20 labLookAfterWCW21 {
        replace `var' =. if `var' == 9999
}
	
	
	
gen labLookAfterMCvWCW21 =.
label variable labLookAfterMCvWCW21 "Who does Lab rep better: the WC or the MC? (-3 to +3, Higher = MC)"
replace labLookAfterMCvWCW21 = labLookAfterMCW21 - labLookAfterWCW21
recode  labLookAfterMCvWCW21 (-3 = -3) (-2 = -2) (-1 = -1) (0=0) (1 = 1) (2 = 2) (3 = 3) (else=.)

gen labLookAfterBAWvWCW21 =.
label variable labLookAfterBAWvWCW21 "Who does Lab rep better: the WC or blacks and Asians? (-3 to +3, Higher = BAW)"
replace labLookAfterBAWvWCW21 = labLookAfterBAW21 - labLookAfterWCW21
recode labLookAfterBAWvWCW21 (-3 = -3) (-2 = -2) (-1 = -1) (0=0) (1 = 1) (2 = 2) (3 = 3) (else=.)

	 
replace labLookAfterWCW21 = labLookAfterWCW21 - 1
replace labLookAfterBAW21 = labLookAfterBAW21 - 1	
replace labLookAfterMCW21 = labLookAfterMCW21 - 1


	
label define nulab 0 "Not at all closely" 1 "Not very closely" 2 "Fairly closely" 3 "Very closely", replace
label values labLookAfterBAW10 labLookAfterBAW19 labLookAfterBAW20 labLookAfterBAW21 labLookAfterMCW10 labLookAfterMCW12 labLookAfterMCW19 labLookAfterMCW20 labLookAfterMCW21 labLookAfterWCW10 labLookAfterWCW12 labLookAfterWCW19 labLookAfterWCW20 labLookAfterWCW21  nulab		
	
label define classbias_1 -3 "Working Class Bias" 0 "Equal" 3 "Middle Class Bias", replace
label define classbias_2 -3 "WC Bias" 0 "Equal" 3 "BME Bias", replace

label values labLookAfterMCvWCW* classbias_1
label values labLookAfterBAWvWCW* classbias_2


keep id wt_new_W21 objectiveclassW21 degreeW21 ethnicityW21 ClassGroup_W21 UKcountryW21 female agegrpW21 warmBMEW11 ethnocentrismw11 labLookAfterMCvWCW21 labLookAfterBAWvWCW21 labIDstrengthW21 voteW21 voteLabW21 lr_scaleW21 al_scaleW21 labLookAfterWCW21 labLookAfterBAW21 labLookAfterMCW21

rename id BES_id
rename wt_new_W21 WEIGHT
rename objectiveclassW21 OCCUPATION
rename degreeW21 DEGREE
rename ethnicityW21 RACE
rename ClassGroup_W21 GROUP
rename lr_scaleW21 VALUES_LR
rename al_scaleW21 VALUES_AL
rename UKcountryW21 COUNTRY
rename female FEMALE
rename agegrpW21 AGEGROUP
rename warmBMEW11 WARM_BME
rename ethnocentrismw11 ETHNOCENTRISM
rename labLookAfterWCW21 LAB_WC
rename labLookAfterBAW21 LAB_BME
rename labLookAfterMCW21 LAB_MC
rename labLookAfterMCvWCW21 LAB_MCoverWC
rename labLookAfterBAWvWCW21 LAB_BMEoverWC
rename voteW21 VOTE_long
rename voteLabW21 VOTE_LAB
rename labIDstrengthW21 LABOUR_ID

gen WAVE = 21
gen MERGE_ID = _n + 93882 //* Last one 93882


save "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\Wave21.dta", replace


*** MERGE ALL 3 WAVES 

use "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\Wave19.dta", clear
merge 1:1 MERGE_ID using "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\Wave10.dta"
drop _merge
save  "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\MERGED_1021.dta", replace

use "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\Wave20.dta", clear
merge 1:1 MERGE_ID using "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\MERGED_1021.dta"
drop _merge
save  "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\MERGED_1021.dta", replace

use "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\Wave21.dta", clear
merge 1:1 MERGE_ID using "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\MERGED_1021.dta"
drop _merge
save  "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\MERGED_1021.dta", replace


use "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data\MERGED_1021.dta", clear



keep BES_id WAVE WEIGHT GROUP LAB_BME LAB_MC LAB_WC LAB_BMEoverWC VOTE_long VOTE_LAB COUNTRY FEMALE AGEGROUP VALUES_LR VALUES_AL LABOUR_ID
order BES_id WAVE WEIGHT GROUP LAB_BME LAB_MC LAB_WC LAB_BMEoverWC VOTE_long VOTE_LAB COUNTRY FEMALE AGEGROUP VALUES_LR VALUES_AL LABOUR_ID


label var BES_id "BES Respondent ID Number" 
label var WEIGHT "Survey Wave Weight"
label var GROUP "Respondent Class-Ethnicity Group (Main Independent Var)"
label var LAB_BME "Perceived Labour Representation: Blacks and Asians (0-3)" 
label var LAB_WC "Perceived Labour Representation: Working Class (0-3)" 
label var LAB_MC "Perceived Labour Representation: Middle Class (0-3)" 
label var LAB_BMEoverWC "Who Does Labour Represent Better: WC or Blacks/Asians (-3 to +3, Higher = BME)"
label var LABOUR_ID "Strength of Labour ID"
label var VOTE_long "Vote Intention"
label var VOTE_LAB "Vote Intention Simplified: Labour (1) vs Other (0)"
label var VALUES_LR "Left-Right Economic Values Score"
label var VALUES_AL "Authoritarian-Libertarian Social Values Score"
label var COUNTRY "UK Country"
label var FEMALE "Female (1) or Male (0)"
label var WAVE "Survey Wave Dummy"


************************************ FIGURE 2 ************************************

svyset [pweight= WEIGHT], psu(BES_id)	

* FIGURE 2A (+ Appendix 24)

reg LAB_WC i.GROUP i.AGEGROUP FEMALE i.COUNTRY i.WAVE  [pweight= WEIGHT], vce(cluster BES_id)
margins, at(GROUP =(1 2 4)) atmeans saving(file1, replace) 
reg LAB_BME i.GROUP i.AGEGROUP FEMALE i.COUNTRY i.WAVE  [pweight= WEIGHT], vce(cluster BES_id)
margins, at(GROUP =(1 2 4)) atmeans saving(file2, replace) 
reg LAB_MC i.GROUP i.AGEGROUP FEMALE i.COUNTRY i.WAVE  [pweight= WEIGHT], vce(cluster BES_id)
margins, at(GROUP =(1 2 4)) atmeans saving(file3, replace) 


* FIGURE 2B (+ Appendix 24)

reg LAB_BMEoverWC i.GROUP i.AGEGROUP FEMALE i.COUNTRY i.WAVE  [pweight= WEIGHT], vce(cluster BES_id)
margins, at(GROUP =(1 2 4)) atmeans saving(file4, replace) 


** Note: Figures themselves created in Excel.


********************* APPENDIX 4 *********************

*** Replication of Table 1

reg LAB_WC c.LAB_BME##i.GROUP i.AGEGROUP FEMALE i.COUNTRY i.WAVE [pweight= WEIGHT], vce(cluster BES_id)

reg LAB_WC c.LAB_BME##i.GROUP VALUES_LR VALUES_AL i.AGEGROUP FEMALE i.COUNTRY i.WAVE [pweight= WEIGHT], vce(cluster BES_id)

reg LAB_WC c.LAB_BME##i.GROUP VALUES_LR VALUES_AL i.LABOUR_ID i.AGEGROUP FEMALE i.COUNTRY i.WAVE [pweight= WEIGHT], vce(cluster BES_id)


*** Replication of Table 2

logit VOTE_LAB c.LAB_BME##i.GROUP c.LAB_MC##i.GROUP c.LAB_WC##i.GROUP i.AGEGROUP FEMALE i.COUNTRY i.WAVE [pweight= WEIGHT], vce(cluster BES_id)

logit VOTE_LAB c.LAB_BME##i.GROUP c.LAB_MC##i.GROUP c.LAB_WC##i.GROUP i.AGEGROUP FEMALE i.COUNTRY i.WAVE VALUES_LR VALUES_AL [pweight= WEIGHT], vce(cluster BES_id)


*** Replication of Table 3

logit VOTE_LAB i.GROUP##c.LAB_BMEoverWC i.AGEGROUP FEMALE i.COUNTRY i.WAVE [pweight= WEIGHT], vce(cluster BES_id)

logit VOTE_LAB i.GROUP##c.LAB_BMEoverWC i.AGEGROUP FEMALE i.COUNTRY i.WAVE VALUES_LR VALUES_AL [pweight= WEIGHT], vce(cluster BES_id)




